package com.boot.springboot.controller;

import com.boot.springboot.pojo.PendingShipment;
import com.boot.springboot.pojo.ResponseMessage;

import com.boot.springboot.pojo.dto.PendingShipmentDto;
import com.boot.springboot.service.IPendingShipmentService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController //接口方法返回对象，装换成json文本
@RequestMapping("/pendingShipment") //localhost:8080/user/**
public class PendingShipmentController {
    @Autowired //自动装配
    IPendingShipmentService pendingShipmentService;
//通过Rest在http协议中实现

    //增加
    @PostMapping //前端请求地址localhost:8080/user method:post
    public ResponseMessage<PendingShipment> add(@Validated @RequestBody PendingShipmentDto pendingShipment){
        PendingShipment pendingShipmentNew=pendingShipmentService.add(pendingShipment);
        return ResponseMessage.success(pendingShipmentNew);
    }
    //查询
    @GetMapping("/{goodId}")
    public ResponseMessage<PendingShipment> get(@PathVariable Integer goodId){
        PendingShipment pendingShipmentNew=pendingShipmentService.get(goodId);
        return ResponseMessage.success(pendingShipmentNew);
    }


    //修改
    @PutMapping
    public ResponseMessage<PendingShipment> edit(@Validated @RequestBody PendingShipmentDto pendingShipment){
        PendingShipment pendingShipmentNew=pendingShipmentService.edit(pendingShipment);
        return ResponseMessage.success(pendingShipmentNew);
    }

    //删除用户
    @DeleteMapping("/{goodId}")
    public ResponseMessage<PendingShipment> delete(@PathVariable Integer goodId){
        pendingShipmentService.delete(goodId);
        return ResponseMessage.delete();
    }
    //查询所有数据
    @GetMapping
    public ResponseMessage<List<PendingShipment>> getAllUsers() {
        List<PendingShipment> pendingShipments = pendingShipmentService.getAllPendingShipments();
        return ResponseMessage.success(pendingShipments);
    }
}
